package com.ashin.leetcode;

import org.junit.Test;

public class L0014 {

 @Test
 public void test(){
     String[]strs={"a"};
     System.out.println(longestCommonPrefix(strs));

 }
    public String longestCommonPrefix(String[] strs) {
        int i=0;
        boolean running=true;
        String prefix="";
        while(running){
            char firstChar=' ';
            for(int j=0;j<strs.length;j++){
                if(strs[j].length()<=0||strs[j].length()<=i){
                    running=false;
                    break;
                }

                if(j==0){
                    firstChar=strs[j].charAt(i);
                    continue;
                }

                if(firstChar!=strs[j].charAt(i)){
                    running=false;
                    break;
                }
            }

            if(running){
                prefix+=firstChar;
                i++;
            }
        }

        return prefix;
    }
}
